package kevin.framework.basic.common.user;

import java.util.List;
import java.util.Map;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import kevin.framework.basic.domain.Menu;
import kevin.framework.basic.domain.User;

/**
 * @ClassName: ILoginUserContext
 * @Description: 登录用户上下文API定义
 * @author kevin.huang
 * @date 2016年1月13日 下午8:40:31
 */
public interface ILoginUserContext {

	/**
	 * 获取当前请求的request对象
	 **/
	public HttpServletRequest getRequest();

	/**
	 * @Title: setUpdateRate @Description: 设置session平滑过期时间的频率 @param rate @throws
	 */
	public void setUpdateRate(int rate);

	/**
	 * @Title: setExpiry @Description: 设置过期时间 @throws
	 */
	public void setExpiry(int expiry);

	/**
	 * @Title: getExpiry @Description: 获取过期时间 @return @throws
	 */
	public int getExpiry();

	/**
	 * @Title: updateExpiry @Description: 更新过期时间 @throws
	 */
	public void updateExpiry(String key) throws Exception;

	/**
	 * 将登录用户保存到session\ memcached
	 * 请在此方法实现内调用  LoginUser.setUserKey(key);
	 * user 当前登录的用户信息 
	 * 返回session/memcached key
	 */
	public String setLoginUser(LoginUser user) throws Exception;

	/**
	 * @Title: logout @Description: 退出系统 @param key @throws
	 */
	public void logout() throws Exception;

	public void logout(String sessionId) throws Exception;

	/**
	 * @Title: setKeyValue @Description: 设置键值对 @param key @param obj @throws
	 */
	public void setKeyValue(String key, Object obj) throws Exception;

	/**
	 * @Title: getKeyValue @Description: 根据键获取值 @param key @return @throws
	 */
	public Object getKeyValue(String key) throws Exception;

	/**
	 * @Title: getCurrentUser @Description: 获取当前登录的用户 @return @throws
	 * Exception @throws
	 */
	public LoginUser getCurrentUser() throws Exception;

	/**
	 * @Title: getSysCookie @Description: 获取系统cookie @param request @return @throws
	 */
	public Cookie getCookie(String key);

	/**
	 * @Title: getIpAddr @Description: 获取登陆ip @param request @return @throws
	 */
	public String getIpAddr();

	/**
	 * @Title: deleteKeyValue @Description: 根据key删除数据 @param key @throws
	 * Exception @throws
	 */
	public void deleteKeyValue(String key) throws Exception;

	/**
	 * 加载用户权限数据
	 * **/	
	public LoginUser loadUserAuthData(User user) throws Exception;
	
	/**
	 * 将登录用户写入cookies
	 * **/
	public String writeLoginCookies(LoginUser user) throws Exception;
	
	/**
	 * 获取登录用户的权限集合
	 * **/
	public Map<String, List<UserFunc>> getLoginUserAuthMap(LoginUser user) throws Exception;
	
	/**获取用户菜单**/
	public List<Menu> getUserMenus(LoginUser user) throws Exception;
}
